#include <SoftwareSerial.h>

#define rxPin 4
#define txPin 5
#define IP_PORT "C192.168.53.226/80\n"
#define HTTP_REQ "GET /rfid.php HTTP/1.0\r\n"
#define HOST_NAME "HOST: localhost\r\n"

enum status{UNBIND,BIND,REQ,DISCON,UNREC};

static status xport_status;
static SoftwareSerial xport=SoftwareSerial(rxPin,txPin);
int tmp=0;

void setup(){
  Serial.begin(9600);
   xport.begin(9600);
  pinMode(rxPin,INPUT);
  pinMode(txPin, OUTPUT);
  xport_status=UNBIND;
}

void loop(){
  conn_http();
}


void conn_http(){
  if(xport_status==UNBIND){
    xport.print(IP_PORT);
    tmp=xport.read();
    switch(tmp){
      case 67://connected
        xport_status=BIND;
        Serial.println("BIND...");
        break;
      case 68://disconnected
        xport_status=DISCON;
        Serial.println("DISCON...");
        break;
      case 78://host unreachable
        Serial.println("UNREC...");
        xport_status=UNREC;
        break;
    }
  }
  if(xport_status==BIND){
    xport.print(HTTP_REQ);
    xport.print(HOST_NAME);
    xport.print("Connection: close\r\n");
    xport.print("\r\n");
    Serial.println("REQ...");
    xport_status=REQ;
  }
  if(xport_status==REQ){
    tmp=xport.read();
    Serial.print(tmp,BYTE);
  }
}
